home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Go Sit In The Corner 1.0 / source / cdev code / cdev meat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  3.2 KB  |  111 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        cdev meat.c
  4.  
  5. Purpose:    This module handles installing & de-installing the VBL.
  6.             
  7.  
  8. Go Sit In The Corner -=- not you, just the cursor
  9. Copyright ©1994, Mark Pilgrim
  10.  
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2 of the License, or
  14. (at your option) any later version.
  15.  
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. GNU General Public License for more details.
  20.  
  21. You should have received a copy of the GNU General Public License
  22. along with this program in a file named "GNU General Public License".
  23. If not, write to the Free Software Foundation, 675 Mass Ave,
  24. Cambridge, MA 02139, USA.
  25.  
  26. \**********************************************************************/
  27.  
  28. #include "cdev globals.h"
  29. #include "cdev meat.h"
  30. #include "cdev prefs.h"
  31. #include "cdev.h"
  32. #include "Retrace.h"
  33. #include "GestaltEQU.h"
  34.  
  35. void RemoveTheVBL(PrefHandle cdevStorage)
  36. {
  37.     if (((**cdevStorage).ourVBLPtr>=(unsigned long)RAMBase) &&
  38.         ((**cdevStorage).ourVBLPtr<(unsigned long)MemTop) &&
  39.         ((**cdevStorage).ourCodePtr>=(unsigned long)RAMBase) &&
  40.         ((**cdevStorage).ourCodePtr<(unsigned long)MemTop) &&
  41.         (GetPtrSize((Ptr)((**cdevStorage).ourVBLPtr))==12+sizeof(VBLTask)) &&
  42.         (VRemove((VBLTask*)((long)((**cdevStorage).ourVBLPtr)+12))==noErr))
  43.     {
  44.         DisposePtr((Ptr)((**cdevStorage).ourVBLPtr));
  45.         DisposeHandle((Handle)((**cdevStorage).ourCodePtr));
  46.     }
  47. }
  48.  
  49. int InstallTheVBL(PrefHandle cdevStorage)
  50. {
  51.     Ptr                tempPtr;
  52.     VBLTask            *vblPtr;
  53.     Handle            ourCode;
  54.     Rect            mainRect;
  55.     
  56.     GetMainScreenBounds(&mainRect);
  57.     ourCode=0L;
  58.     ourCode=GetResource('vbl ', 999);
  59.     if (ourCode!=0L)
  60.     {
  61.         if (*ourCode==0L)
  62.             LoadResource(ourCode);
  63.         if (*ourCode==0L)
  64.             return kCantGetResource;
  65.         
  66.         HLock(ourCode);
  67.         DetachResource(ourCode);
  68.         
  69.         tempPtr=NewPtrSys(12+sizeof(VBLTask));
  70.         *((unsigned char*)tempPtr)=(**cdevStorage).always;
  71.         *((unsigned long*)((long)tempPtr+4))=(**cdevStorage).numTicks;
  72.         *((int*)((long)tempPtr+8))=(((**cdevStorage).whichCorner==0x00) ||
  73.             ((**cdevStorage).whichCorner==0x03)) ? mainRect.left : mainRect.right;
  74.         *((int*)((long)tempPtr+10))=(((**cdevStorage).whichCorner==0x00) ||
  75.             ((**cdevStorage).whichCorner==0x01)) ? mainRect.top : mainRect.bottom;
  76.         
  77.         vblPtr = (VBLTask*) ((long)tempPtr+12);
  78.         vblPtr->qType = vType;
  79.         vblPtr->vblAddr = (ProcPtr) *ourCode;
  80.         vblPtr->vblCount = 1;
  81.         vblPtr->vblPhase = 0;
  82.         VInstall(vblPtr);
  83.         (**cdevStorage).ourCodePtr=(unsigned long)ourCode;
  84.         (**cdevStorage).ourVBLPtr=(unsigned long)tempPtr;
  85.     }
  86.     else return kCantGetResource;
  87.  
  88.     return prefs_allsWell;
  89. }
  90.  
  91. void GetMainScreenBounds(Rect* theRect)
  92. {
  93.     long                oldA5;
  94.     QDGlobals            qd;
  95.     GrafPort            gp;
  96.     GrafPtr                savePort;
  97.  
  98.     GetPort(&savePort);
  99.     oldA5 = SetA5((long)&qd.end);
  100.     InitGraf(&qd.thePort);
  101.     OpenPort(&gp);
  102.     SetCursor(&qd.arrow);
  103.     
  104.     SetRect(theRect, qd.screenBits.bounds.left, qd.screenBits.bounds.top,
  105.         qd.screenBits.bounds.right, qd.screenBits.bounds.bottom);
  106.     
  107.     ClosePort(&gp);
  108.     SetA5(oldA5);
  109.     SetPort(savePort);
  110. }
  111.